package org.linlinjava.litemall.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.linlinjava.litemall.admin.beans.annotation.LogAnno;
import org.linlinjava.litemall.admin.service.AdminLumiereMaterialClassificationService;
import org.linlinjava.litemall.admin.vo.AdminLumiereMaterialClassificationVO;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LumiereMaterialClassification;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.InvocationTargetException;

@Api(tags = "原料分类API")
@RestController
@RequestMapping("admin/materialClassification")
@RequiredArgsConstructor
public class AdminLumiereMaterialClassificationController {

    private final AdminLumiereMaterialClassificationService adminLumiereMaterialClassificationService;

    @ApiOperation("原料分类-同步")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "limit",value = "数量"),
            @ApiImplicitParam(name = "page",value = "当前页"),
            @ApiImplicitParam(name = "classificationName",value = "分类名称")
    })
    @LogAnno
    @GetMapping("/sync")
    public ResponseUtil.Response sync(){
        return adminLumiereMaterialClassificationService.syncLumiereMaterialClassifications();
    }


    @ApiOperation("原料分类-查询原料分类")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "limit",value = "数量"),
            @ApiImplicitParam(name = "page",value = "当前页"),
            @ApiImplicitParam(name = "classificationName",value = "分类名称")
    })
    @LogAnno
    @GetMapping("/list")
    public ResponseUtil.Response list(AdminLumiereMaterialClassificationVO lumiereMaterialClassificationVO,
                                         @RequestParam("limit")Integer limit,
                                         @RequestParam("page")Integer page) throws InvocationTargetException, IllegalAccessException {
        return adminLumiereMaterialClassificationService.listLumiereMaterialClassifications(lumiereMaterialClassificationVO,limit,page);
    }

    @ApiOperation("原料分类-查询原料分类分组")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "limit",value = "数量"),
            @ApiImplicitParam(name = "page",value = "当前页"),
            @ApiImplicitParam(name = "classificationName",value = "分类名称")
    })
    @LogAnno
    @GetMapping("/listGroupBy")
    public ResponseUtil.Response listGroupBy() {
        return adminLumiereMaterialClassificationService.listGroupBy();
    }

    @ApiOperation("原料分类-查询原料分类分组")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "limit",value = "数量"),
            @ApiImplicitParam(name = "page",value = "当前页"),
            @ApiImplicitParam(name = "classificationName",value = "分类名称")
    })
    @LogAnno
    @GetMapping("/listFormulaGroupBy")
    public ResponseUtil.Response listFormulaGroupBy() {
        return adminLumiereMaterialClassificationService.listFormulaGroupBy();
    }


    @ApiOperation("原料分类-查询原料分类选项")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "limit",value = "数量"),
            @ApiImplicitParam(name = "page",value = "当前页"),
            @ApiImplicitParam(name = "classificationName",value = "分类名称")
    })
    @LogAnno
    @GetMapping("/option-list")
    public ResponseUtil.Response optionList(){
        return adminLumiereMaterialClassificationService.optionListLumiereMaterialClassifications();
    }

    @ApiOperation("原料分类-新增原料分类")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "classificationName",value = "分类名称"),
            @ApiImplicitParam(name = "classificationColour",value = "分类颜色"),
            @ApiImplicitParam(name = "number",value = "序号"),
            @ApiImplicitParam(name = "remark",value = "备注"),
    })
    @LogAnno
    @PostMapping("/add")
    public ResponseUtil.Response add(AdminLumiereMaterialClassificationVO lumiereMaterialClassificationVO)  {
        return adminLumiereMaterialClassificationService.addLumiereMaterialClassification(lumiereMaterialClassificationVO);
    }

    @ApiOperation("原料分类-编辑原料分类")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "classificationName",value = "分类名称"),
            @ApiImplicitParam(name = "classificationColour",value = "分类颜色"),
            @ApiImplicitParam(name = "number",value = "序号"),
            @ApiImplicitParam(name = "remark",value = "备注"),
    })
    @LogAnno
    @PutMapping ("/update")
    public ResponseUtil.Response update(AdminLumiereMaterialClassificationVO lumiereMaterialClassificationVO)  {
        return adminLumiereMaterialClassificationService.updateLumiereMaterialClassification(lumiereMaterialClassificationVO);
    }

    @ApiOperation("原料分类-删除原料分类")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "id"),
    })
    @LogAnno
    @DeleteMapping("/delete")
    public ResponseUtil.Response delete(Integer id)  {
        return adminLumiereMaterialClassificationService.deleteLumiereMaterialClassification(id);
    }



}
